package main

import (
	"fmt"
	"net/http"
	"time"
)

func index(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "fuck the world!")
	cookie, _ := r.Cookie("username")
	if cookie2, err := r.Cookie("username2"); err == nil {
		fmt.Fprintf(w, cookie2.Value)
	}

	if cookie, err := r.Cookie("username"); err == nil {
		fmt.Fprintf(w, cookie.Value)
	}
	fmt.Fprintf(w, cookie.Value)
}

func setCookie(w http.ResponseWriter, r *http.Request) {
	expiration := time.Now()
	expiration = expiration.AddDate(1, 0, 0)
	cookie := http.Cookie{Name: "username", Value: "sbb", Expires: expiration}
	http.SetCookie(w, &cookie)
}

func main() {
	http.HandleFunc("/", index)
	http.HandleFunc("/setCookie", setCookie)
	err := http.ListenAndServe(":20009", nil)
	if err != nil {
		fmt.Println("设置失败！", err)
	}
	fmt.Println("vim-go")
}
